import request from '@/utils/request'
import type {
  addProjectParams,
  projectQueryParams,
  addProgressParams,
} from '@/api/back-management/pension-facilities-project/interface'
import type { Response, PageDataList } from '@/utils/type'
import type { AxiosResponse } from 'axios'

export interface ProjectDataResp {
  filingTime?: string
  pkid: string
  projectName: string
  investAmount?: string
  projectAddress: string
  projectType: string
  updateTime?: string
}

/**
 * 获取养老设施项目列表
 *
 * @param {projectQueryParams} params 查询参数
 */
export const queryProjectList = (
  params: projectQueryParams
): Promise<Response<PageDataList<ProjectDataResp>>> => {
  return request('/residential/pension/query', {
    method: 'GET',
    params,
  })
}

/**
 * 查询养老设施项目详情
 *
 * @param {string} pkid 主键id
 */
export const getProjectDetail = (pkid: string) => {
  return request('/residential/pension/get', {
    method: 'GET',
    params: {
      pkid,
    },
  }) as Promise<Response<any>>
}

/**
 * 上传文件
 */
export const uploadFile = (params: any) => {
  return request('/resource/file/upload/file', {
    method: 'POST',
    data: params,
  }) as Promise<Response<string>>
}

/**
 * 删除文件
 *
 * @param {string} fileId 文件id
 */
export const deleteFile = (fileId: string) => {
  return request('resource/file/delete', {
    method: 'DELETE',
    params: {
      fileId,
    },
  }) as Promise<Response<any>>
}

/**
 * 新增养老设施
 *
 * @param {addProjectParams} params 新增参数
 */
export const addProject = (params: addProjectParams) => {
  return request('/residential/pension/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 删除养老设施项目
 *
 * @param {string} pkid 主键id
 */
export const deleteProject = (pkid: string) => {
  return request('/residential/pension/delete', {
    method: 'DELETE',
    params: {
      pkid,
    },
  }) as Promise<Response<any>>
}

/**
 * 编辑养老设施项目
 *
 *
 * @param {addProjectParams} params 新增参数
 */
export const editProject = (params: addProjectParams) => {
  return request(`/residential/pension/update`, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 查询项目进展
 *
 * @param {string} projectId 项目id
 */
export const getProjectProgress = (projectId: string, stageType: string) => {
  return request('/residential/stage/get', {
    method: 'GET',
    params: {
      projectId,
      stageType,
    },
  }) as Promise<Response<any>>
}

/**
 * 新增项目进展
 *
 * @param {addProgressParams} params 新增参数
 */
export const addProjectProgress = (
  projectId: string,
  params: addProgressParams
) => {
  return request('/residential/stage/add?projectId=' + projectId, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 修改项目进展
 *
 *
 * @param {addProgressParams} params 新增参数
 */
export const editProjectProgress = (
  projectId: string,
  params: addProgressParams
) => {
  return request('/residential/stage/update?projectId=' + projectId, {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 获取下拉选项
 *
 */
export const getResidentialDict = () => {
  return request('/residential/dict/get', {
    method: 'GET',
  }) as Promise<Response<any>>
}

/**
 * 获取月报菜单
 *
 */
export const getReportMenuDict = () => {
  return request('/residential/dict/get/10', {
    method: 'GET',
  }) as Promise<Response<any>>
}

/**
 * 养老设施项目批量下载
 *
 * @basicId {string} basicId
 *
 */
export const downloadPensionList = (
  basicId: string
): Promise<AxiosResponse<Blob>> => {
  return request(`/residential/pension/exportExcel?basicId=${basicId}`, {
    responseType: 'blob',
  })
}
